{
 "cells": [
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**stations**\n",
    "\n",
    "StationReference = Name | MayBeInitial | Platforms\n",
    "\n",
    "|Name | MayBeInitial | Platforms |  \n",
    " |--|--|--|  \n",
    "|a = 武汉东站城际场 | 1 | 5, 1, 6, 4, 2, 3 |\n",
    "|b = 武汉东站存车线 | 1 | 1 |  \n",
    "|c = 余花联络线花山南方向 | 1 | 1, 2 |  \n",
    "|d = 余花联络线余家湾方向 | 1 | 2, 1 |  \n",
    "|e = 武咸城际咸宁南方向 | 1 | 1, 2 |  \n",
    "|f = 武昌南环线武昌南方向 | 1 | 1, 2 |  \n",
    "|g = 武汉东站普速场(没车) | 1 | 7, 4, 2, 1, 3, 5 |  \n",
    "|h = 武昌南环线何刘方向 | 1 | 2, 1 |  \n",
    "\n",
    "**timetable**  \n",
    " Format: \n",
    " ReportingNumber TrainType MaxSpeedKmph TrainComposition Flags : StationVisit1 StationVisit2 ...  \n",
    "\n",
    " StationVisit format:  \n",
    " StationReferencePlatformNumberFromDurationMinutes  \n",
    "\n",
    " TrainType format:  \n",
    " COMMUTER | FREIGHT | IC | URBAN  \n",
    "\n",
    " TrainComposition format:  \n",
    " vvv...  \n",
    " Each v represents one vehicle. L = locomotive (or control post), C = cargo car, P = passenger car  \n",
    " \n",
    " Flags format:  \n",
    " ff  \n",
    " Each f is one flag. 0 = flag not set, 1 = flag set, X = position not used  \n",
    " Flag positions:  \n",
    " 1 unused (X)  \n",
    " 2 NoBrakingPenalization - if set (1), train does NOT receive penalization when braking at signals  \n",
    "\n",
    "\n",
    "**例子**  \n",
    "|列车编号|类型|最高时速|动拖布置|flag|车站1|车站2|车站3|   \n",
    "|--|--|--|--|--|--|--|--|  \n",
    "|C5627| COMMUTER| 200| LPPL| X1 :| b#1#07:03:00#0| a#3#07:06:00#20 |c#1#07:29:00#0 |  \n",
    "\n"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**车次相关信息**  \n",
    "    车次信息不变 默认commuter  \n",
    "    依照类型设置最高速度 D->200 G->300  \n",
    "    车辆细节 先默认 MTTM 后续修改长编或者重连?  \n",
    "  \n",
    "\n",
    "**停站相关信息**  \n",
    "    仅三点式 进场车站 停站 离场车站  \n",
    "    车站 筛选所有车次始发终到，设置字典更改进场离场  \n",
    "    股道指定 随机指定？  \n",
    "  \n",
    "\n",
    "**表格信息**  \n",
    "从路路通截图导出为Excel进行处理  \n",
    "![格式](武汉东时刻.png)  \n",
    "始发站和终到站更换为进场车站和离场车站  \n",
    "  \n",
    "\n",
    "**车站信息**  \n",
    "![车站](武汉东站.png)  \n",
    "单个车站及进场离场布置  \n",
    "  "
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**库函数部分及常规列车信息部分**  \n",
    "导入库函数，处理表格以及替换字符并导出  \n",
    "使用字典建立常规信息的映射关系  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy\n",
    "import pandas\n",
    "import datetime\n",
    "import random\n",
    "\n",
    "Excelpath = \"whd.xlsx\"  # Excel时刻表文件路径\n",
    "TextPath=\"trains武汉东.txt\" #游戏时刻表文件路径\n",
    "speed = {'K': '120', 'T': '140', 'Z': '160',\n",
    "         'D': '200', 'C': '200', 'G': '300'}  # 速度映射关系\n",
    "# 车站-编号,股道,股道到达及用时映射关系\n",
    "# 股道到达映射关系.可到达股道,图片左右侧线路key值相同则掉向,\n",
    "station = {'余花联络线余家湾方向': ['d', '135', 0, 10], '武咸城际咸宁南方向': ['e', '135', 0, 10], '武汉东站城际场': ['a', '123456', -1, 0], \n",
    "           '武汉东站存车线': ['b', '123456', 0, 3], '余花联络线花山南方向': ['c', '246', 1, 3], }\n",
    "ThisStation = '武汉东站城际场'\n",
    "# track = {}\n",
    "# 车型关系--待筛选，默认短编\n",
    "marshalling = {}\n",
    "\n",
    "# 始发终到映射关系--待筛选\n",
    "dst = {}\n",
    "\n",
    "# 股道到达,图片左右侧线路,,key值不同则掉向\n",
    "# turnst = {'武九客专武汉方向': 0, '武九客专鄂州方向': 1, '武冈城际黄冈方向': 1}\n",
    "\n",
    "trainDF = pandas.DataFrame(\n",
    "    columns=['列车编号', '类型', '最高时速', '动拖布置', 'flag'])  # 列车整体信息\n",
    "arriveStDF = pandas.DataFrame(columns=['车站名称', '股道', '到达时间', '停站时间'])  # 进场信息\n",
    "stopStDF = pandas.DataFrame(columns=['车站名称', '股道', '到达时间', '停站时间'])  # 停站信息\n",
    "leaveStDF = pandas.DataFrame(columns=['车站名称', '股道', '到达时间', '停站时间'])  # 离场信息\n",
    "\n",
    "# 存储字符串形式的最终结果\n",
    "trainList = []\n",
    "arriveStList = []\n",
    "stopStList = []\n",
    "leaveStList = []\n"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**读取表格及数据处理部分**  \n",
    ">1,读取表格并去除空行  \n",
    ">2,从车次提取速度等级  \n",
    ">3,筛选始发站终到站建立替换字典  \n",
    "  \n",
    "  \n",
    "**车次字符串生成部分**\n",
    ">1,车次信息部分\n",
    ">>车次号,类型,动拖布置及flag保持默认  \n",
    ">>速度等级依照KTZDG等区分映射  \n",
    "\n",
    ">2,停站部分  \n",
    ">>停站2(主要车站) 到时及停站时间来自表格部分  股道随机  \n",
    ">>进场及离场部分 依照游戏先期测试进行平移推算  股道依照上下行安排  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "    车次名称        到时        开时  始发站  终到站\n",
      "0  C5627  07:06:00  07:26:00  武汉东  黄冈东\n",
      "1  D5770  08:10:00  08:17:00  大冶北  云梦东\n",
      "2  D5762  09:15:00  09:25:00  黄冈东   仙桃\n",
      "3  C5051  09:32:00  09:36:00  咸宁南   阳新\n",
      "4  D5862  09:42:00  09:46:00   阳新  咸宁南\n",
      "{'武汉东', '希水南', '汉口', '黄冈西', '黄冈东', '咸宁南', '大冶北', '阳新', '武穴北', '蕲春南', '云梦东', '仙桃', '宜昌东', '十堰东'}\n"
     ]
    }
   ],
   "source": [
    "# 读取文件\n",
    "sheet = pandas.read_excel(io=Excelpath)\n",
    "\n",
    "sheet = sheet.dropna()\n",
    "sheet=sheet.reset_index(drop=True)\n",
    "\n",
    "print(sheet.head())\n",
    "\n",
    "trainInfo = sheet[\"车次名称\"].to_frame()  # 车辆信息\n",
    "#统计始发终到车站信息\n",
    "ts=pandas.concat([sheet[\"始发站\"].value_counts(),sheet[\"终到站\"].value_counts()])\n",
    "totalStation=ts.index\n",
    "\n",
    "print(set(list(totalStation))) #所有始发站和终到站统计"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'武汉东': '武汉东站存车线',\n",
       " '希水南': '余花联络线花山南方向',\n",
       " '汉口': '余花联络线余家湾方向',\n",
       " '黄冈西': '余花联络线花山南方向',\n",
       " '黄冈东': '余花联络线花山南方向',\n",
       " '咸宁南': '武咸城际咸宁南方向',\n",
       " '大冶北': '余花联络线花山南方向',\n",
       " '阳新': '余花联络线花山南方向',\n",
       " '武穴北': '余花联络线花山南方向',\n",
       " '蕲春南': '余花联络线花山南方向',\n",
       " '云梦东': '余花联络线余家湾方向',\n",
       " '仙桃': '余花联络线余家湾方向',\n",
       " '宜昌东': '余花联络线余家湾方向',\n",
       " '十堰东': '余花联络线余家湾方向'}"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 手动建立映射关系\n",
    "ArrLeaveSt = {'武汉东':'武汉东站存车线', \n",
    "              '希水南':'余花联络线花山南方向', \n",
    "              '汉口':'余花联络线余家湾方向', \n",
    "              '黄冈西':'余花联络线花山南方向', \n",
    "              '黄冈东':'余花联络线花山南方向', \n",
    "              '咸宁南':'武咸城际咸宁南方向', \n",
    "              '大冶北':'余花联络线花山南方向', \n",
    "              '阳新':'余花联络线花山南方向', \n",
    "              '武穴北':'余花联络线花山南方向', \n",
    "              '蕲春南':'余花联络线花山南方向', \n",
    "              '云梦东':'余花联络线余家湾方向', \n",
    "              '仙桃':'余花联络线余家湾方向', \n",
    "              '宜昌东':'余花联络线余家湾方向', \n",
    "              '十堰东':'余花联络线余家湾方向'}\n",
    "ArrLeaveSt \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>列车编号</th>\n",
       "      <th>类型</th>\n",
       "      <th>最高时速</th>\n",
       "      <th>动拖布置</th>\n",
       "      <th>flag</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>C5627</td>\n",
       "      <td>COMMUTER</td>\n",
       "      <td>200</td>\n",
       "      <td>LPPL</td>\n",
       "      <td>X1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>D5770</td>\n",
       "      <td>COMMUTER</td>\n",
       "      <td>200</td>\n",
       "      <td>LPPL</td>\n",
       "      <td>X1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>D5762</td>\n",
       "      <td>COMMUTER</td>\n",
       "      <td>200</td>\n",
       "      <td>LPPL</td>\n",
       "      <td>X1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>C5051</td>\n",
       "      <td>COMMUTER</td>\n",
       "      <td>200</td>\n",
       "      <td>LPPL</td>\n",
       "      <td>X1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>D5862</td>\n",
       "      <td>COMMUTER</td>\n",
       "      <td>200</td>\n",
       "      <td>LPPL</td>\n",
       "      <td>X1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    列车编号        类型 最高时速  动拖布置 flag\n",
       "0  C5627  COMMUTER  200  LPPL   X1\n",
       "1  D5770  COMMUTER  200  LPPL   X1\n",
       "2  D5762  COMMUTER  200  LPPL   X1\n",
       "3  C5051  COMMUTER  200  LPPL   X1\n",
       "4  D5862  COMMUTER  200  LPPL   X1"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#'列车编号','类型','最高时速','动拖布置','flag' 列车整体信息\n",
    "\n",
    "for index,row in trainInfo.iterrows():\n",
    "    trainNum=row[\"车次名称\"]\n",
    "    maxspeed=speed.get(trainNum[0])#有字头的列车\n",
    "    if maxspeed==None: #最高速度未找到\n",
    "        maxspeed='120' #普客\n",
    "    \n",
    "    #trainTC=marshalling.get() #动拖布置\n",
    "    trainDF.loc[index]=[trainNum,\"COMMUTER\",maxspeed,\"LPPL\",\"X1\"]\n",
    "    trainList.append(\"{0} {1} {2} {3} {4} : \".format(trainNum,\"COMMUTER\",maxspeed,\"LPPL\",\"X1\"))\n",
    "trainDF.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [],
   "source": [
    "# arriveStList=pandas.DataFrame(columns=['车站名称','股道','到达时间','停站时间'])#进场信息\n",
    "# stopiveStList=pandas.DataFrame(columns=['车站名称','股道','到达时间','停站时间'])#停站信息\n",
    "# leaveStList=pandas.DataFrame(columns=['车站名称','股道','到达时间','停站时间'])#离场信息\n",
    "# stationInfo = sheet[[\"到时\", \"开时\",\"始发站\", \"终到站\"]]  # 时间及停站信息\n",
    "\n",
    "for index, row in sheet.iterrows():\n",
    "    arriveSt = ArrLeaveSt.get(row[\"始发站\"])\n",
    "    leaveSt = ArrLeaveSt.get(row[\"终到站\"])\n",
    "\n",
    "    # 上下行编号区分车辆进场股道为1,2道\n",
    "\n",
    "    if int(row[\"车次名称\"].strip()[-1]) % 2 == 0:\n",
    "        arriveTrack = 2  # 偶数位上行车\n",
    "    else:\n",
    "        arriveTrack = 1  # 奇数下行\n",
    "    # 依照掉向区分离场股道 数值相同即为同一侧需掉向，不同即为不掉向顺向行驶\n",
    "    if (station.get(arriveSt))[2] == (station.get(leaveSt))[2]:\n",
    "        leaveTrack = 3-arriveTrack  # 2->1,1->2\n",
    "    else:\n",
    "        leaveTrack = arriveTrack\n",
    "\n",
    "    # 停站股道,依照映射随机选择\n",
    "    stopTrack = random.choice((station.get(arriveSt)[1]))\n",
    "\n",
    "    at=row[\"到时\"]\n",
    "    lt=row[\"开时\"]\n",
    "    # 统一时间格式\n",
    "    strTime1 = datetime.datetime.strptime(str(at), \"%H:%M:%S\")\n",
    "    strTime2 = datetime.datetime.strptime(str(lt), \"%H:%M:%S\")\n",
    "\n",
    "    stopTime = (strTime2-strTime1).seconds/60  # 分钟为单位的停站时间\n",
    "\n",
    "    arrTime1=strTime1-datetime.timedelta(minutes=(station.get(arriveSt))[3])\n",
    "    #print((str(arrTime1))[10,-1])\n",
    "    arrTime2=str(arrTime1.strftime('%Y-%m-%d %H:%M:%S'))[-8:]\n",
    "    arrTime=datetime.datetime.strptime(arrTime2, \"%H:%M:%S\")\n",
    "\n",
    "    leaveTime1=strTime2+datetime.timedelta(minutes=(station.get(leaveSt))[3])\n",
    "    leaveTime2=str(leaveTime1.strftime('%Y-%m-%d %H:%M:%S'))[-8:]\n",
    "    leaveTime=datetime.datetime.strptime(leaveTime2, \"%H:%M:%S\")\n",
    "\n",
    "    # 进场\n",
    "    arriveStDF.loc[index] = [arriveSt, arriveTrack, arrTime2, 0]\n",
    "    arriveStList.append(\"{0}#{1}#{2}#{3}\".format(\n",
    "        (station.get(arriveSt))[0], arriveTrack, arrTime2, 0))\n",
    "    # 停站\n",
    "    stopStDF.loc[index] = [ThisStation, stopTrack, row[\"到时\"], stopTime]\n",
    "    stopStList.append(\"{0}#{1}#{2}#{3}\".format(\n",
    "        (station.get(ThisStation))[0], stopTrack, row[\"到时\"], int(stopTime)))\n",
    "\n",
    "    # 离场\n",
    "    leaveStDF.loc[index] = [leaveSt, leaveTrack, leaveTime2, 0]\n",
    "    leaveStList.append(\"{0}#{1}#{2}#{3}\".format(\n",
    "        (station.get(leaveSt))[0], leaveTrack, leaveTime2, 0))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "         车站名称  股道      到达时间  停站时间\n",
      "0     武汉东站存车线   1  07:03:00     0\n",
      "1  余花联络线花山南方向   2  08:07:00     0\n",
      "2  余花联络线花山南方向   2  09:12:00     0\n",
      "3   武咸城际咸宁南方向   1  09:22:00     0\n",
      "4  余花联络线花山南方向   2  09:39:00     0 \n",
      "       车站名称 股道      到达时间  停站时间\n",
      "0  武汉东站城际场  6  07:06:00  20.0\n",
      "1  武汉东站城际场  2  08:10:00   7.0\n",
      "2  武汉东站城际场  4  09:15:00  10.0\n",
      "3  武汉东站城际场  3  09:32:00   4.0\n",
      "4  武汉东站城际场  4  09:42:00   4.0 \n",
      "          车站名称  股道      到达时间  停站时间\n",
      "0  余花联络线花山南方向   1  07:29:00     0\n",
      "1  余花联络线余家湾方向   2  08:27:00     0\n",
      "2  余花联络线余家湾方向   2  09:35:00     0\n",
      "3  余花联络线花山南方向   1  09:39:00     0\n",
      "4   武咸城际咸宁南方向   2  09:56:00     0\n"
     ]
    }
   ],
   "source": [
    "print(arriveStDF.head(),'\\n',stopStDF.head(),'\\n',leaveStDF.head())"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**最终车次结果**  \n",
    "合并车辆信息和停站信息  \n",
    "  \n",
    "**导出部分**  \n",
    "导出为train.txt手动附加原文件头部之后替换原时刻表文件  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['C5627 COMMUTER 200 LPPL X1 : b#1#07:03:00#0 a#6#07:06:00#20 c#1#07:29:00#0 ',\n",
       " 'D5770 COMMUTER 200 LPPL X1 : c#2#08:07:00#0 a#2#08:10:00#7 d#2#08:27:00#0 ',\n",
       " 'D5762 COMMUTER 200 LPPL X1 : c#2#09:12:00#0 a#4#09:15:00#10 d#2#09:35:00#0 ',\n",
       " 'C5051 COMMUTER 200 LPPL X1 : e#1#09:22:00#0 a#3#09:32:00#4 c#1#09:39:00#0 ',\n",
       " 'D5862 COMMUTER 200 LPPL X1 : c#2#09:39:00#0 a#4#09:42:00#4 e#2#09:56:00#0 ',\n",
       " 'D5741 COMMUTER 200 LPPL X1 : d#1#09:42:00#0 a#5#09:52:00#6 c#1#10:01:00#0 ',\n",
       " 'D5778 COMMUTER 200 LPPL X1 : c#2#10:13:00#0 a#4#10:16:00#4 d#2#10:30:00#0 ',\n",
       " 'D5742 COMMUTER 200 LPPL X1 : c#2#11:44:00#0 a#2#11:47:00#4 d#2#12:01:00#0 ',\n",
       " 'D5745 COMMUTER 200 LPPL X1 : d#1#12:08:00#0 a#5#12:18:00#6 c#1#12:27:00#0 ',\n",
       " 'D5852 COMMUTER 200 LPPL X1 : c#2#12:20:00#0 a#4#12:23:00#10 b#2#12:36:00#0 ',\n",
       " 'D5765 COMMUTER 200 LPPL X1 : d#1#12:35:00#0 a#1#12:45:00#9 c#1#12:57:00#0 ',\n",
       " 'D5853 COMMUTER 200 LPPL X1 : b#1#12:47:00#0 a#1#12:50:00#11 c#1#13:04:00#0 ',\n",
       " 'D5881 COMMUTER 200 LPPL X1 : e#1#13:12:00#0 a#1#13:22:00#4 c#1#13:29:00#0 ',\n",
       " 'C5023 COMMUTER 200 LPPL X1 : e#1#13:32:00#0 a#3#13:42:00#8 b#2#13:53:00#0 ',\n",
       " 'C5024 COMMUTER 200 LPPL X1 : b#2#13:57:00#0 a#3#14:00:00#20 e#1#14:30:00#0 ',\n",
       " 'C5056 COMMUTER 200 LPPL X1 : c#2#15:27:00#0 a#2#15:30:00#5 e#2#15:45:00#0 ',\n",
       " 'D5886 COMMUTER 200 LPPL X1 : c#2#15:32:00#0 a#2#15:35:00#4 e#2#15:49:00#0 ',\n",
       " 'D5746 COMMUTER 200 LPPL X1 : c#2#15:46:00#0 a#6#15:49:00#4 d#2#16:03:00#0 ',\n",
       " 'D5854 COMMUTER 200 LPPL X1 : c#2#15:42:00#0 a#4#15:45:00#10 b#2#15:58:00#0 ',\n",
       " 'D5766 COMMUTER 200 LPPL X1 : c#2#16:15:00#0 a#4#16:18:00#5 d#2#16:33:00#0 ',\n",
       " 'D5855 COMMUTER 200 LPPL X1 : b#1#16:08:00#0 a#2#16:11:00#10 c#1#16:24:00#0 ',\n",
       " 'D5758 COMMUTER 200 LPPL X1 : c#2#17:04:00#0 a#6#17:07:00#5 d#2#17:22:00#0 ',\n",
       " 'D5856 COMMUTER 200 LPPL X1 : c#2#17:37:00#0 a#4#17:40:00#10 b#2#17:53:00#0 ',\n",
       " 'C5067 COMMUTER 200 LPPL X1 : e#1#17:42:00#0 a#1#17:52:00#4 c#1#17:59:00#0 ',\n",
       " 'D5895 COMMUTER 200 LPPL X1 : e#1#17:50:00#0 a#1#18:00:00#4 c#1#18:07:00#0 ',\n",
       " 'D5857 COMMUTER 200 LPPL X1 : b#1#17:57:00#0 a#4#18:00:00#11 c#1#18:14:00#0 ',\n",
       " 'D5777 COMMUTER 200 LPPL X1 : d#1#18:34:00#0 a#5#18:44:00#13 c#1#19:00:00#0 ',\n",
       " 'D5769 COMMUTER 200 LPPL X1 : d#1#19:23:00#0 a#1#19:33:00#8 c#1#19:44:00#0 ',\n",
       " 'D5761 COMMUTER 200 LPPL X1 : d#1#19:33:00#0 a#1#19:43:00#5 c#1#19:51:00#0 ',\n",
       " 'C5068 COMMUTER 200 LPPL X1 : c#2#19:37:00#0 a#2#19:40:00#6 e#2#19:56:00#0 ',\n",
       " 'D5896 COMMUTER 200 LPPL X1 : c#2#19:43:00#0 a#2#19:46:00#4 e#2#20:00:00#0 ',\n",
       " 'D5858 COMMUTER 200 LPPL X1 : c#2#20:19:00#0 a#4#20:22:00#10 b#2#20:35:00#0 ',\n",
       " 'D5859 COMMUTER 200 LPPL X1 : b#1#20:37:00#0 a#1#20:40:00#11 c#1#20:54:00#0 ',\n",
       " 'D5757 COMMUTER 200 LPPL X1 : d#1#20:54:00#0 a#1#21:04:00#4 c#1#21:11:00#0 ',\n",
       " 'C5512 COMMUTER 200 LPPL X1 : c#2#21:36:00#0 a#4#21:39:00#4 d#2#21:53:00#0 ']"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "timeTable =open(file=TextPath,mode=\"a\")\n",
    "finalRes=[]\n",
    "for i in range(0,len(arriveStList)):\n",
    "    tstr=\"{0}{1} {2} {3} \".format(trainList[i],arriveStList[i],stopStList[i],leaveStList[i])\n",
    "    finalRes.append(tstr)\n",
    "    tstr1=tstr+'\\n'\n",
    "    timeTable.writelines(tstr1)\n",
    "\n",
    "timeTable.close()\n",
    "finalRes\n",
    "\n",
    "\n"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.2"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
